--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_hinanawi_tenshi = General:new(extension, "hy_hinanawi_tenshi", "jin_k", 3, 3, General.Female)
    local read_temperament = fk.CreateSkill {
        name = "read_temperament",
    }
    read_temperament:addEffect(fk.GameStart, {
        anim_type = "masochism",
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(read_temperament.name) or player.dead then
                return false
            end
            return true
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local cards = room:getNCards(#room.alive_players)
            player:addToPile("$temperament", cards, false, read_temperament.name)
        end,
    })
    read_temperament:addEffect(fk.AfterDrawPileShuffle, {
        anim_type = "masochism",
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(read_temperament.name) or player.dead or (#player.room.draw_pile + #player.room.discard_pile) < #player.room.alive_players then
                return false
            end
            return true
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local cards = room:getNCards(#room.alive_players)
            player:addToPile("$temperament", cards, false, read_temperament.name)
        end,
    })
    read_temperament:addEffect(fk.Damaged, {
        anim_type = "masochism",
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(read_temperament.name) or player.dead then
                return false
            end
            return target == player and #player:getPile("$temperament") > 0
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            HY.ReplaceHandCardToTempNew(player, player:getPile("$temperament"))
            local card = HY.AskForCard(player, 1, 1, false, read_temperament.name, false, nil, "read_temperament_prompt")
            HY.ReverseHandCardFromTempNew(player)
            room:moveCards({
                proposer = player,
                from = player,
                ids = card,
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonPutIntoDiscardPile,
                skillName = read_temperament.name,
            })
            local cards = room:getNCards(1)
            player:addToPile("$temperament", cards, false, read_temperament.name)
        end,
    })
    read_temperament:addEffect(fk.Damage, {
        anim_type = "masochism",
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(read_temperament.name) or player.dead then
                return false
            end
            return target == player and #player:getPile("$temperament") > 0
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            HY.ReplaceHandCardToTempNew(player, player:getPile("$temperament"))
            local card = HY.AskForCard(player, 1, 1, false, read_temperament.name, false, nil, "read_temperament_prompt")
            HY.ReverseHandCardFromTempNew(player)
            room:moveCards({
                proposer = player,
                from = player,
                ids = card,
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonPutIntoDiscardPile,
                skillName = read_temperament.name,
            })
            local cards = room:getNCards(1)
            player:addToPile("$temperament", cards, false, read_temperament.name)
        end,
    })
    read_temperament:addEffect(fk.TurnEnd, {
        anim_type = "masochism",
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(read_temperament.name) or player.dead then
                return false
            end
            return table.any(HY.GetTurnDiscardPile(player.room), function(card)
                return card:getMark("temperament-turn") ~= 0
            end)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local cards = table.filter(HY.GetTurnDiscardPile(player.room), function(card)
                return card:getMark("temperament-turn") ~= 0
            end)
            room:obtainCard(player, cards, true, fk.ReasonPrey, player)
        end,
    })
    read_temperament:addEffect(fk.AfterCardsMove, {
        can_refresh = function(self, event, target, player, data)
            return player:hasSkill(self, true, true) and table.any(data, function(move)
                return table.any(move.moveInfo, function(info)
                    return info.fromArea == Card.PlayerSpecial and info.fromSpecialName == "$temperament"
                end)
            end)
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local ids = player:getMark("temperament")
            if type(ids) ~= "table" then
                ids = {}
            end
            for _, move in ipairs(data) do
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerSpecial and info.fromSpecialName == "$temperament" then
                        room:setCardMark(Fk:getCardById(info.cardId), "temperament-turn", 1)
                    end
                end
            end
        end,
    })
    local wonderful_heaven = fk.CreateSkill {
        name = "wonderful_heaven",
    }
    wonderful_heaven:addEffect("viewas", {
        mute_card = false,
        anim_type = "offensive",
        pattern = "fire__slash",
        expand_pile = "$temperament",
        card_num = 1,
        times = function(self, player)
            return 2 - player:usedSkillTimes(wonderful_heaven.name, Player.HistoryPhase)
        end,
        card_filter = function(self, player, to_select, selected)
            return #selected == 0 and table.contains(player:getPile("$temperament"), to_select)
        end,
        prompt = "wonderful_heaven_prompt",
        view_as = function(self, player, cards)
            if #cards ~= 1 then
                return
            end
            local card = Fk:cloneCard("fire__slash")
            table.insertIfNeed(card.skillNames, "wonderful_heaven")
            table.insertIfNeed(card.subcards, cards[1])
            return card
        end,
        enabled_at_play = function(self, player)
            return player:hasSkill(self) and player:usedSkillTimes(wonderful_heaven.name, Player.HistoryPhase) < 2 and #player:getPile("$temperament") > 0
        end,
        enabled_at_response = Util.FalseFunc,
    })
    wonderful_heaven:addEffect("targetmod", {
        bypass_distances = function(self, player, skill, card, to)
            return card and type(card) == "table" and card:isInstanceOf(Card) and skill.trueName == "slash_skill" and table.contains(card.skillNames, "wonderful_heaven")
        end,
        bypass_times = function(self, player, skill, scope, card, to)
            return card and type(card) == "table" and card:isInstanceOf(Card) and skill.trueName == "slash_skill" and table.contains(card.skillNames, "wonderful_heaven")
        end
    })
    wonderful_heaven:addEffect(fk.PreCardUse, {
        can_refresh = function(self, event, target, player, data)
            return table.contains(data.card.skillNames, "wonderful_heaven")
        end,
        on_refresh = function(self, event, target, player, data)
            local card = data.card
            local id = card.subcards[1]
            player.room:moveCards({
                proposer = player,
                from = player,
                ids = { id },
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonPutIntoDiscardPile,
                skillName = wonderful_heaven.name,
            })
            table.removeOne(card.subcards, id)
        end,
    })
    wonderful_heaven:addEffect(fk.CardUseFinished, {
        can_refresh = function(self, event, target, player, data)
            return table.contains(data.card.skillNames, "wonderful_heaven") and (not data.damageDealt or table.any(data.damageDealt, function(damage)
                return damage <= 0
            end)) and player.room.current == target
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local e = room.logic:getCurrentEvent()
            while e.parent and e.parent.event ~= GameEvent.Phase do
                e = e.parent
            end
            e:addExitFunc(function()
                e.parent:shutdown()
            end)
        end,
    })
    extension:loadSkillSkels { read_temperament, wonderful_heaven }
    hy_hinanawi_tenshi:addSkill("read_temperament")
    hy_hinanawi_tenshi:addSkill("wonderful_heaven")
    Fk:loadTranslationTable {
        ["hy_hinanawi_tenshi"] = "比那名居天子",
        ["#hy_hinanawi_tenshi"] = "顽劣的纯真",
        ["illustrator:hy_hinanawi_tenshi"] = "here",
        ["designer:hy_hinanawi_tenshi"] = "黑曜人形",
        ["cv:hy_hinanawi_tenshi"] = "",

        ["read_temperament"] = "气辨",
        [":read_temperament"] = "游戏开始时或牌堆洗牌后，你将牌堆顶与存活人数等量张牌作为“气”扣置于武将牌上。在你造成或受到伤害后，你移去一张“气”并将牌堆顶的牌作为“气”扣置于武将牌上。每回合结束时，你获得弃牌堆中所有本回合移去的“气”。",
        ["$temperament"] = "气",
        ["read_temperament_prompt"] = "气辨：你须移去一张“气”",

        ["wonderful_heaven"] = "绯想",
        [":wonderful_heaven"] = "出牌阶段限两次，你可以移去一张“气”并视为使用一张无距离与次数限制的火【杀】，若没有角色受到此【杀】的伤害，你结束此阶段。",
        ["wonderful_heaven_prompt"] = "绯想：你可以移去一张“气”并视为使用一张无距离与次数限制的火【杀】",
    }
end
